home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / message.zip / MESSAGE.C < prev    next >
Text File  |  1992-05-08  |  34KB  |  849 lines

  1. /*
  2. ╔════════════════════════════════════════════════════════════════════════════╗
  3. ║                               MESSAGE MINDER                               ║
  4. ║                                                                            ║
  5. ║                     By Brian Hill           March, 1992                    ║
  6. ║                                                                            ║
  7. ║       Message minder is a TSR program which will display a message         ║
  8. ║  from the serial port on the screen. The message is cleared when the       ║
  9. ║  user presses any key. The format for sending a messge is as follows:      ║
  10. ║  1) The com port on the sending machine should be set to 9600, N, 8, 1.    ║
  11. ║  2) A message is started with a SOH character. <alt> 1 will generate.      ║
  12. ║  3) A message is completed with a EOT character. <alt> 4 will generate.    ║
  13. ║                                                                            ║
  14. ║ *NOTE when the user enters the un-install command: message u  the program  ║
  15. ║  will only un-install properly if it is the last TSR loaded.               ║
  16. ║                                                                            ║
  17. ╚════════════════════════════════════════════════════════════════════════════╝
  18.                                                                             */
  19. #pragma check_stack( off )     // turn off stack checking
  20. #pragma check_pointer( off )   // do not check for null pointers
  21. #pragma pack(1)                // byte align data to conserve memory
  22.  
  23. #include <string.h>
  24. #include <stdlib.h>
  25. #include < conio.h>
  26. #include < stdio.h>
  27. #include <  bios.h>
  28. #include <   dos.h>
  29.  
  30. #define SOH  1          // start of header
  31. #define EOT  4          // end of transmit
  32. #define ESC 27          // ASCII value of escape key
  33. #define ENTER 13        // ASCII value for enter key
  34. #define BACKSPACE 8     // ASCII value for backspace key
  35. #define NORM_VID 7      // normal video attribute
  36.  
  37.  
  38. /*
  39. ╔════════════════════════════════════════════════════════════════════════════╗
  40. ║             Interrupt routines and function pointers                       ║
  41. ╚════════════════════════════════════════════════════════════════════════════╝
  42.                                                                             */
  43. void (interrupt _far *oldclock)(void);  // old clock handler
  44. void (interrupt _far *olddosok)(void);  // old dosok handler
  45. void (interrupt _far *oldkeybd)(void);  // old keyboard handler
  46. void  interrupt _far keybd(void);       // our keyboard handler
  47. void  interrupt _far clock(void);       // our clock routine
  48. void  interrupt _far dosok(void);       // our dosok handler
  49. void  interrupt _far serial(void);      // Our serial port ISR
  50.  
  51.  
  52.  
  53.  
  54.  
  55. /*
  56. ╔════════════════════════════════════════════════════════════════════════════╗
  57. ║           Functions our program will call when active                      ║
  58. ╚════════════════════════════════════════════════════════════════════════════╝
  59.                                                                             */
  60. void memputs(char x,char y,char *string,char attrib); // display string
  61. void save_screen(void);                 // save user's screen in screen[]
  62. void restore_screen(void);              // restore user's screen
  63. void display_message(void);             // display our message to screen
  64. void draw_border(int type);             // make a message border
  65. void doit(void);                        // activate TSR
  66. void memputs(char x, char y,char *string, char attrib);
  67. void send_message(void);                // Get message and transmit
  68. void display_message(void);             // show received message
  69. void xmit_char(char ch);                // sent a character out COM 1
  70. int  chk_xmit(void);                    // Is it OK to send a character?
  71. int  mem_gets(char *szStr,int xyStrRow, int xyStrCol);  // get a string
  72. void write_char(int x,int y,char ch,char attrib);       // write char at x,y
  73. void goto_xy(int x, int y);                             // move cursor
  74. void get_xy(int *x, int *y);            // get cursor pos -w- BIOS
  75. void beep(void);                        // short "beep" thru PC's speaker
  76.  
  77. void main();
  78. void init(void);                        // set up program
  79. int  check_install(int num);            // check if program resident
  80. void interrupt _far un_install (void);  // pointer to un-install function
  81.  
  82. /*
  83. ╔════════════════════════════════════════════════════════════════════════════╗
  84. ║                            Program data                                    ║
  85. ╚════════════════════════════════════════════════════════════════════════════╝
  86.                                                                             */
  87. char buffer[81];                        // our serial input buffer
  88. char userscreen[481];                   // save user's screen here
  89. int  port;                              // com1 port address
  90. int  _far *keyboard_status;             // check if <ctrl> is pressed.
  91. char _far *video = (char far *)0xB8000000;   // pointer to color video memory
  92. char _far *mode  = (char far *)0x00400049;   // pointer to CRT video mode
  93.  
  94. char _huge *tsrstack;                   // our stack space
  95. char _huge *tsrbottom;                  // huge pointer to our PSP
  96. char _huge *userstack;                  // user's stack space
  97.  
  98. char string[] = {"_MESSAGE"};           // TSR signature
  99. struct tsrinfo
  100. {
  101.      char *signature;                   // pointer to TSR signature
  102.      void (interrupt _far *un_install_ptr)(void);   // pointer to un-install
  103.  
  104. } transient, _huge *resident;
  105.  
  106.  
  107.  
  108.  
  109. /*
  110. ╔════════════════════════════════════════════════════════════════════════════╗
  111. ║                             Flags                                          ║
  112. ╚════════════════════════════════════════════════════════════════════════════╝
  113.                                                                             */
  114. char _far request_to_run;               // Has message arrived?
  115. char _far tsr_running;                  // Is menu displayed?
  116. _segment(dosseg);                       //  Segment of inDos flag.
  117. char _based(dosseg) *indos;             //  Based pointer to InDos flag.
  118. char video_mode_flag;                   // Waiting for appropriate video mode?
  119.  
  120.  
  121. /*
  122. ╔════════════════════════════════════════════════════════════════════════════╗
  123. ║                               Code                                         ║
  124. ╚════════════════════════════════════════════════════════════════════════════╝
  125.                                                                             */
  126. void main(int argc, char **argv)
  127. {
  128.  
  129.  unsigned tsrsize;               // memory needed for residence
  130.  int i;                          // a scratch pad variable
  131.  char ch;
  132.  
  133. /*
  134.     ╔═════════════════════════════════════════════════════════════════════╗
  135.     ║                    Claculate program size                           ║
  136.     ╚═════════════════════════════════════════════════════════════════════╝
  137.                                                                            */
  138.  _asm mov WORD PTR tsrstack[0], sp              // save our stack address
  139.  _asm mov WORD PTR tsrstack[2], ss
  140.  FP_SEG(tsrbottom) = _psp;                      // save PSP address
  141.  FP_OFF(tsrbottom) = 0;
  142.  tsrsize = ((tsrstack - tsrbottom) >> 4) + 1;   // calculate program size
  143.  
  144. /*
  145.     ╔═════════════════════════════════════════════════════════════════════╗
  146.     ║                   Is the program already installed?                 ║
  147.     ╚═════════════════════════════════════════════════════════════════════╝
  148.                                                                             */
  149.  
  150.  transient.un_install_ptr = un_install; // establish pointer to un_install
  151.  transient.signature = (char *) string; //set pointer in structure to signatre
  152.  resident = (struct tsrinfo _huge *)&transient;// establish pointer to struct
  153.  
  154.  if( (argc == 2) && (*argv[1] == 'u') )        // uninstall?
  155.  {
  156.      if(check_install(1))
  157.         printf("\n\nProgram Un-installed.");
  158.  
  159.      else printf("\n\nProgram was not resident.");
  160.      exit(1);
  161.  }
  162.  
  163.  else i